<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>国检--${fns:getConfig('productName')}</title>
<%@include file="/common/uihead.jsp" %>
<%@ include file="/common/jqGridHead.jsp"%>
</head>
<body>
<ul class="nav nav-tabs" style="margin:0 4px;margin-bottom:4px;">
		<li class="active"><a href="${ctx}/countryCheck/showList.do?left=${fns:encodeParam(left)}&parentId=${fns:encodeParam(parentId)}">
			<i class="icon icon-list"></i>&nbsp;<span>国检列表</span></a></li>
			<sec:authorize ifAnyGranted="ROLE_gsj_editor">
			<c:if test="${add}">
		<li><a href="${ctx}/countryCheck/input.do?left=${fns:encodeParam(left)}&parentId=${fns:encodeParam(parentId)}">
		     <i class="icon icon-edit"></i>&nbsp;<span>新增</span></a></li>
		     </c:if>
		     </sec:authorize>
	</ul>
	<tags:message content="${msg}" />
<form id="mainForm" class="form-horizontal" role="form" method="get"  name="mainForm">
<div class="breadcrumb form-search" style="background-color: #f5f5f5;">
			<div>
				<label>关键字:</label>
				<input type="text" oninput="queryForGrid('mainForm','jqGrid')" onporpertychange="queryForGrid('mainForm','jqGrid')" 
				 name="filter_LIKES_projectName_OR_content_OR_remark" value="${filter_LIKES_projectName_OR_content_OR_remark}" placeholder="国检项目查询" />
			</div>
		</div>
  <table id="jqGrid"></table>
  <div id="jqGridPager"></div> 
</form>
	<script type="text/javascript">
	    var path = "${ctx}";
		$(document).ready(function()
		{
			var jqgridH = $(window).height()-335;       
			$("#jqGrid").jqGrid(
			{ url : '${ctx}/countryCheck/list.do?filter_EQS_countryOrProvince=0',
			  mtype : "GET",
			  datatype : "json",
			  page : 1,
			  viewrecords: true,
			  colModel:[<sec:authorize ifAnyGranted="ROLE_gsj_release, ROLE_gsj_editor">
				{ label : "操作", name : "id", 
					  width : 300,   align : 'center', sortable : false, search : false ,
					  classes:'ui-jqgrid-optClass',
					  formatter: function (cellValue, options, rowObject){
							return formatterOpt(cellValue, rowObject['status'],rowObject['menuListSize'], rowObject['showHref']);
					  }
				},</sec:authorize>
                {
           	        label: '项目名称',
           	        name: 'projectName',
           	     	align:'center',
           	        width: 225
                },{
           	        label: '起始时间',
           	        name: 'startTime',
           	     	align:'center',
           	        width: 100
                },
                {
           	        label: '结束时间',
           	        name: 'endTime',
           	     	align:'center',
           	        width: 100
                },
                {
           	        label: '检查菜单长度',
           	        name: 'menuListSize',
           	     	align:'center',
           	     	hidden:true,
           	        width: 100
                },
                {
           	        label: '详情地址',
           	        name: 'showHref',
           	     	align:'center',
           	     	hidden:true,
           	        width: 100
                },
                {
           	        label: '概述',
           	        name: 'content',
           	     	align:'center',
           	        width: 175
                },
                {
           	        label: '状态',
           	        name: 'status',
           	     	align:'center',
           	        width: 80,
	           	    formatter: function (cellValue, options, rowObject){
						if(cellValue=='0'){
							return "<span style='color:red'>未发布</span>";
						} else{
							return "<span style='color:green'>已发布</span>";
						}
					 }
                },
                {
           	        label: '备注',
           	        name: 'remark',
           	     	align:'center',
           	        width: 225
                }
						],
			autowidth : false,width:$(window).width()-248, height : jqgridH,scrollOffset:0, shrinkToFit : 400, rowNum : 10, viewrecords : true, rownumbers : true,
			jsonReader:{
    			root: "result",
    			page: "currentPage",
    			total: "totalPages",
    			records: "totalCount",
    			repeatitems: true,
    			cell: "cell",
    			id: "id",
    			userdata: "userdata",
    			subgrid: {root:"results", repeatitems: true, cell:"cell"}
    		},
    		prmNames: {
				page:"pageNo",
				rows:"pageSize",
				sort: "orderBy",
				order: "order",
				search:"_search",
				nd:"nd", id:"id",
				oper:"oper",
				editoper:"edit",
				addoper:"add",
				deloper:"del",
				subgridid:"id",
				npage: null,
				totalrows:"totalCounts"
			}, 
			rowList :[10,20,30], 
			pager : "#jqGridPager"
			});
		});
		
		function formatterOpt(id, status,menuListSize, href) {
// 			var  show = "<a href='${ctx}/repair/show.do?left=402880f65b8f5473015b8f5830810003&projectId="+id+"&top=${fns:encodeParam(parentId)}&leftChild=402880f65b8f5473015b8f8e11df0020&menuId=402880f65b8f5473015b8fa2f947004a' title='详情'><i class='icon-eye' style='padding-top:2px;'></i>&nbsp;详情</a>&nbsp;&nbsp;";
			var  show = "<a href='${ctx}/"+href+"&projectId="+id+"&top=${fns:encodeParam(parentId)}' title='详情'><i class='icon-eye' style='padding-top:2px;'></i>&nbsp;详情</a>&nbsp;&nbsp;";
			var editor = "<a href='${ctx}/countryCheck/input.do?left=${fns:encodeParam(left)}&parentId=${fns:encodeParam(parentId)}&id="+id+"' title='修改'><i class='icon icon-edit' style='margin-top:4px;'></i>&nbsp;修改</a>&nbsp;&nbsp;";
			var release = "<a href='javascript:void(0);'onclick='release(\"${fns:encodeParam(left)}\",\"${fns:encodeParam(parentId)}\",\""+id+"\");' title='发布'><i class='icon-send' style='margin-top:4px;'></i>&nbsp;发布</a>&nbsp;&nbsp;";
			var del ="<a href='javascript:void(0);' onclick='del(\"${fns:encodeParam(left)}\",\"${fns:encodeParam(parentId)}\",\""+id+"\");' title='删除'><i class='icon-close' style='margin-top:3px;'></i>&nbsp;删除</a>";
			var selfCheck = "<a href='${ctx}/check/maintenance.do?left=${fns:encodeParam(left)}&parentId=${fns:encodeParam(parentId)}&projectId="+id+"' title='自检'><i class='icon icon-edit' style='margin-top:4px;'></i>&nbsp;自检</a>&nbsp;&nbsp;";
			var content = "";
			if(menuListSize >0){
				content += show;
			}
			//如果项目已经发布了  则不再出现发布选择入口
			if(status == "0"){
				<sec:authorize ifAnyGranted="ROLE_gsj_release">
				content += release;
				</sec:authorize>
				<sec:authorize ifAnyGranted="ROLE_gsj_editor">
				content += editor+del;
				</sec:authorize>
				content += selfCheck;
			} else {
				<sec:authorize ifAnyGranted="ROLE_gsj_editor">
				content += del;
				</sec:authorize>
			}
			return content;
			
		}

		function  del(left, parentId, id){
			var url = "${ctx}/countryCheck/delete.do?left="+left+"&parentId="+parentId+"&id="+id;
			console.log(url);
			$.jBox.confirm("确认要删掉该项目吗？", '系统提示', function(v, h, f) {
				if (v == 'ok') {
					loading('正在提交，请稍等...');
					$.ajax({
						type : "POST",
						dataType : "json",
						url : url,
						success : function(data) {
							$.jBox.tip("删除成功", 'info');
							$("#jqGrid").trigger("reloadGrid");
							setTimeout("$.jBox.closeTip()", 1000);
							location.reload();
						},
						error : function(data) {
						}
					});
				}
			}, {
				buttonsFocus : 1
			});
		};
		
		function  release(left, parentId, id){
			var url = "${ctx}/countryCheck/release.do?left="+left+"&parentId="+parentId+"&id="+id;
			console.log(url);
			$.jBox.confirm("确认要发布该项目吗？<br/>发布之后，该项目检查内容将不能编辑", '系统提示', function(v, h, f) {
				if (v == 'ok') {
					loading('正在提交，请稍等...');
					$.ajax({
						type : "POST",
						dataType : "json",
						url : url,
						success : function(data) {
							$.jBox.tip("发布成功", 'info');
							$("#jqGrid").trigger("reloadGrid");
							setTimeout("$.jBox.closeTip()", 1000);
							location.reload();
						},
						error : function(data) {
						}
					});
				}
			}, {
				buttonsFocus : 1
			});
		};
		
</script>

</body>
</html>
